package cn.tedu.springmvc.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler({
            NullPointerException.class,
            ClassCastException.class
    })
    public String handlerNullPointException(Throwable e) {
        e.printStackTrace();
        return "Error,NullPointException or ClassCastException";
    }

    @ExceptionHandler(NumberFormatException.class)
    public String handlerNumberFormatException(Throwable e) {
        e.printStackTrace();
        return "Error,NumberFormatException!";
    }

    @ExceptionHandler
    public String handlerThrowable(Throwable e) {
        e.printStackTrace();
        return "Error,Throwable!";
    }
}
